﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExtJSExtender.Controls.Grid
{
    public class GridRowCollection : ICollection
    {
        #region 属性

        private ArrayList _list = null;

        #endregion

        #region 构造函数

        public GridRowCollection()
        {
            this._list = new ArrayList();
        }

        #endregion

        #region 公用方法

        public void Add(GridRow row)
        {
            this._list.Add(row);
        }

        public GridRow Add()
        {
            GridRow row = new GridRow();
            this.Add(row);
            return row;
        }

        public GridRow Add(string HeaderText, string DataField)
        {
            GridRow row = this.Add();


            return row;
        }

        public void AddRange(GridRow[] rows)
        {
            this._list.AddRange(rows);
        }

        public int IndexOf(GridRow row)
        {
            return this._list.IndexOf(row);
        }

        public GridRow this[int index]
        {
            get
            {
                var obj = this._list[index];
                if (obj != null)
                    return (GridRow)obj;

                return null;
            }
        }

        public void Remove(GridRow row)
        {
            this._list.Remove(row);
        }

        public void RemoveAt(int index)
        {
            this._list.RemoveAt(index);
        }

        #endregion

        #region ICollection 成员

        public void CopyTo(Array array, int index)
        {
            this._list.CopyTo(array, index);
        }

        public int Count
        {
            get { return this._list.Count; }
        }

        public bool IsSynchronized
        {
            get { return false; }
        }

        public object SyncRoot
        {
            get
            {
                return this;
            }
        }

        #endregion

        #region IEnumerable 成员

        public IEnumerator GetEnumerator()
        {
            return this._list.GetEnumerator();
        }

        #endregion
    }
}
